﻿using System;
using System.Collections.Generic;

namespace Core.Res
{

    [Serializable]
    public class AssetInfo
    {
        public string Path;

        public string Bundle;

        public string[] Relies;
        public string[] BeRelies;
    }

    [Serializable]
    public class BundleInfo
    {
        public string Name;

        public string MD5;

        public int Offset;
        public int Position;

        public string[] Assets;
    }

    [Serializable]
    public class ResList
    {
        public AssetInfo[] Assets;
        public BundleInfo[] Bundles;

    }

    public class ResDict
    {
        private Dictionary<string, AssetInfo> assets = new();
        private Dictionary<string, BundleInfo> bundles = new();

        public void SetData(ResList resList)
        {
            assets.Clear();
            bundles.Clear();

            for (int i = 0; i < resList.Assets.Length; i++)
            {
                var asset = resList.Assets[i];
                assets[asset.Path] = asset;
            }

            for (int i = 0; i < resList.Bundles.Length; i++)
            {
                var bundle = resList.Bundles[i];
                bundles[bundle.Name] = bundle;
            }
        }

        public AssetInfo GetAsset(string name)
        {
            return assets.GetValueOrDefault(name);
        }

        public BundleInfo GetBundle(string name)
        {
            return bundles.GetValueOrDefault(name);
        }
    }
}
